package com.moxiao.yfjh.module.blind.common;

import com.moxiao.yfjh.module.blind.dal.dataobject.basicSetting.BlindBasicSettingDO;
import com.moxiao.yfjh.module.blind.dal.dataobject.member.BlindMemberUserDO;
import com.alibaba.fastjson.JSON;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @version 1.0
 * @Author zhk
 * @Date 2024/2/29 14:17
 **/


@Component
public class CommonRedisUtils {
    @Resource
    private StringRedisTemplate stringRedisTemplate;


    private static final String MEMBER_REDIS_KEY = "blind_member_user:";
    private static final String BASIC_SETTING = "basic_setting:";

    /**
     * 用户会员信息
     * @param memberUser
     */
    public void createMemberToRedis(Long memberUserId, BlindMemberUserDO memberUser){
        String memberRedisKey = MEMBER_REDIS_KEY + memberUserId;
        stringRedisTemplate.opsForValue().set(memberRedisKey, JSON.toJSONString(memberUser));
    }
    public void delMemberToRedis(Long memberUserId){
        String memberRedisKey = MEMBER_REDIS_KEY + memberUserId;
        stringRedisTemplate.delete(memberRedisKey);
    }

    public BlindMemberUserDO getMemberToRedis(Long memberUserId){
        String memberRedisKey = MEMBER_REDIS_KEY + memberUserId;
        String s = stringRedisTemplate.opsForValue().get(memberRedisKey);
        if (StringUtils.isNotEmpty(s)){
            return JSON.parseObject(s, BlindMemberUserDO.class);
        }
        return null;
    }


    /**
     * 配置信息
     * @param id
     * @return
     */
    public BlindBasicSettingDO getBasicToRedis(Long id){
        String s = stringRedisTemplate.opsForValue().get(BASIC_SETTING + id);
        if (StringUtils.isNotEmpty(s)){
            return JSON.parseObject(s, BlindBasicSettingDO.class);
        }
        return null;
    }

    public void createBasicToRedis(Long id, BlindBasicSettingDO basicSettingDO){
        String basicRedisKey = BASIC_SETTING + id;
        stringRedisTemplate.opsForValue().set(basicRedisKey, JSON.toJSONString(basicSettingDO));
    }
    public void delBasicToRedis(Long id){
        String basicRedisKey = BASIC_SETTING + id;
        stringRedisTemplate.delete(basicRedisKey);
    }








}
